
incl = open_dataset('data/final_long') %>%
  group_by(cycle) %>%
  summarise(across(c(d_val, r_val), ~ sum(.x, na.rm=T))) %>%
  collect()

## same as above:
# incl = tribble(
#   ~cycle, ~d_val, ~r_val,
#   2012, 324328176, 314198845,
#   2016, 364272543, 116102032,
#   2020, 547717312, 529697865
# )

setDT(incl)

incl = melt(incl, 1)
incl$cand = c('obama', 'clinton', 'biden', 'romney', 'trump', 'trump')

x = fread('summary_data/camp_summ.csv') ## from FEC summary data + creation/joining/04_join_fec.R

x = x[,.(unitem = sum(unitemized+take_out), item = sum(itemized-take_out)),.(cand,cycle)]
x = x[c(1:4, 6:5),]
x$id = 1:nrow(x)

merge(x, incl, by = c('cand', 'cycle')) %>%
  mutate(
    pct_match_item = round(value/item,3),
    pct_match_raised = round(value/(item+unitem),3)
    ) %>%
  arrange(id)
